package com.sl.plugin.step.json;


import com.sl.core.engine.meta.impl.AbstractProcessCompDescriptor;
import com.sl.core.engine.step.ProcessCompService;
import com.sl.core.engine.step.impl.AbstractProcessComp;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 *
 */
public class JsonToMapComp extends AbstractProcessComp<List<Map<String, Object>>, Map<Object, Map<String, Object>>> implements ProcessCompService {


    public JsonToMapComp(AbstractProcessCompDescriptor abstractProcessCompDescriptor) {
        super(abstractProcessCompDescriptor);
    }

    @Override
    public Map<Object, Map<String, Object>> input(List<Map<String, Object>> driver) {
        String fieldCode = meta.getStrAttr("fieldCode");
        Map<Object, Map<String, Object>> key = driver.stream().collect(Collectors.toMap(v -> v.get(fieldCode), Function.identity(), (k1, k2) -> k1));
        return key;
    }
}
